<?php
require_once("mysql.inc.php");
require_once("checkLogin.inc.php");

if(isset($_GET["a"])) {
	getTrash();
}

function getTrash() {

	$result = mysql_query("SELECT * FROM `trash` ORDER BY `date`");
	$num = mysql_num_rows($result);
	$i = 1;
	
	$no_info = "Niet bekend";
	
	//create new dom document
	$doc = new DomDocument('1.0');
	$root = $doc->createElement("results");
	$doc->appendChild($root);
	
	//create first element containing amount of results
	$n = $doc->createElement("num");
	$n->appendChild($doc->createTextNode($num));
	$root->appendChild($n);
	
	while($fetch = mysql_fetch_array($result)) {
		
		$t = $doc->createElement("title$i");
		if(!empty($fetch["title"])) {
			$t->appendChild($doc->createTextNode($fetch["title"]));
		}
		else {
			$t->appendChild($doc->createTextNode($no_info));
		}		
		$root->appendChild($t);
			
		$a = $doc->createElement("author$i");
		if(!empty($fetch["author"])) {
			$a->appendChild($doc->createTextNode($fetch["author"]));
		}
		else {
			$a->appendChild($doc->createTextNode($no_info));
		}		
		$root->appendChild($a);
			
		$a2 = $doc->createElement("author2_$i");
		if(!empty($fetch["author2"])) {
			$a2->appendChild($doc->createTextNode($fetch["author2"]));
		}
		else {
			$a2->appendChild($doc->createTextNode($no_info));
		}
		$root->appendChild($a2);
			
		$genre = $doc->createElement("genre$i");
		if(!empty($fetch["genre"])) {
			$genre->appendChild($doc->createTextNode($fetch["genre"]));
		}
		else {
			$genre->appendChild($doc->createTextNode($no_info));
		}	
		$root->appendChild($genre);
			
		$theme = $doc->createElement("theme1_$i");
		if(!empty($fetch["theme1"])) {
			$theme->appendChild($doc->createTextNode($fetch["theme1"]));
		}
		else {
			$theme->appendChild($doc->createTextNode($no_info));
		}
		$root->appendChild($theme);
			
		$theme2 = $doc->createElement("theme2_$i");
		if(!empty($fetch["theme2"])) {
			$theme2->appendChild($doc->createTextNode($fetch["theme2"]));	
		}
		else {
			$theme2->appendChild($doc->createTextNode($no_info));
		}
		$root->appendChild($theme2);
			
		$price = $doc->createElement("price$i");
		if(!empty($fetch["price"])) {
			$price->appendChild($doc->createTextNode($fetch["price"]));	
		}
		else {
			$price->appendChild($doc->createTextNode($no_info));
		}
		$root->appendChild($price);
			
		$age = $doc->createElement("age$i");
		if(!empty($fetch["age"])) {
			$age->appendChild($doc->createTextNode($fetch["age"]));	
		}
		else {
			$age->appendChild($doc->createTextNode($no_info));
		}
		$root->appendChild($age);
			
		$publisher = $doc->createElement("publish$i");
		if(!empty($fetch["publisher"])) {
			$publisher->appendChild($doc->createTextNode($fetch["publisher"]));	
		}
		else {
			$publisher->appendChild($doc->createTextNode($no_info));
		}
		$root->appendChild($publisher);
			
		$place = $doc->createElement("place$i");
		if(!empty($fetch["place"])) {
			$place->appendChild($doc->createTextNode($fetch["place"]));	
		}
		else {
			$place->appendChild($doc->createTextNode($no_info));
		}
		$root->appendChild($place);
			
		$material = $doc->createElement("material$i");
		if(!empty($fetch["material"])) {
			$material->appendChild($doc->createTextNode($fetch["material"]));	
		}
		else {
			$material->appendChild($doc->createTextNode($no_info));
		}
		$root->appendChild($material);	
		
		$date = $doc->createElement("date$i");
		$date->appendChild($doc->createTextNode($fetch["date"]));
		$root->appendChild($date);
		
		$i++;
	}
	
	echo $doc->saveXML();
}
?>